package future;

import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class Test07 {
    public static void main(String[] args) {
        ListeningExecutorService service = MoreExecutors.newDirectExecutorService();
        SettableFuture<Double> settableFuture = SettableFuture.create();
        service.submit(() -> {
            Double result = Math.pow(2, 2);
            settableFuture.set(result);
            return result;
        });
        try {
            System.out.println(settableFuture.get(2, TimeUnit.SECONDS));
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }
}
